home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
By the Book
/
Learn C++ (CodeWarrior)
/
Chap 09.02 - multInherit
/
multInherit.cp
< prev
next >
Wrap
Text File
|
1995-10-21
|
1KB
|
99 lines
#include <iostream.h>
#include <string.h>
const short kMaxStringLength = 40;
//--------------------------------------- Predator
class Predator
{
private:
char favoritePrey[ kMaxStringLength ];
public:
Predator( char *prey );
~Predator();
};
Predator::Predator( char *prey )
{
strcpy( favoritePrey, prey );
cout << "Favorite prey: "
<< prey << "\n";
}
Predator::~Predator()
{
cout << "Predator destructor was called!\n\n";
}
//--------------------------------------- Pet
class Pet
{
private:
char favoriteToy[ kMaxStringLength ];
public:
Pet( char *toy );
~Pet();
};
Pet::Pet( char *toy )
{
strcpy( favoriteToy, toy );
cout << "Favorite toy: "
<< toy << "\n";
}
Pet::~Pet()
{
cout << "Pet destructor was called!\n";
}
//-------------------------- Cat:Predator,Pet
class Cat : public Predator, public Pet
{
private:
short catID;
static short lastCatID;
public:
Cat( char *prey, char *toy );
~Cat();
};
Cat::Cat( char *prey, char *toy ) :
Predator( prey ), Pet( toy )
{
catID = ++lastCatID;
cout << "catID: " << catID
<< "\n---------\n";
}
Cat::~Cat()
{
cout << "Cat destructor called: catID = "
<< catID << "...\n";
}
short Cat::lastCatID = 0;
//--------------------------------------- main()
int main()
{
Cat TC( "Mice", "Ball of yarn" );
Cat Benny( "Crickets", "Bottle cap" );
Cat Meow( "Moths", "Spool of thread" );
return 0;
}